package com.xhs.main.service.rmt.impl;

import com.xhs.main.dao.rmt.RmtPurchasingApplyDao;
import com.xhs.main.dao.rmt.RmtPurchasingApplyItemsDao;
import com.xhs.main.entity.rmt.RmtPurchasingApply;
import com.xhs.main.entity.rmt.RmtPurchasingApplyItems;
import com.xhs.main.service.rmt.RmtPurchasingApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZS
 * @create 2020-10-20-11:22
 */
@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class RmtPurchasingApplyServiceImpl implements RmtPurchasingApplyService {
    @Autowired
    RmtPurchasingApplyDao rmtPurchasingApplyDao;
    @Autowired
    RmtPurchasingApplyItemsDao rmtPurchasingApplyItemsDao;

    @Transactional
    @Override
    public void addPurchasingApply(RmtPurchasingApply rmtPurchasingApply) {
        rmtPurchasingApplyDao.insertPurchasingApply(rmtPurchasingApply);
        for (RmtPurchasingApplyItems r : rmtPurchasingApply.getRmtPurchasingApplyItems()
        ) {
            rmtPurchasingApplyItemsDao.insertPurchasingApplyItems(r);
        }
    }

    @Override
    public List<RmtPurchasingApply> selectAllPurchasingApply() {
        List<RmtPurchasingApply> rmtPurchasingApplies = rmtPurchasingApplyDao.selectAllPurchasingApply();
        return rmtPurchasingApplies;
    }

    public List<RmtPurchasingApplyItems> selectAllPurchasingApplyItems() {
        List<RmtPurchasingApplyItems> rmtPurchasingApplyItemsList = rmtPurchasingApplyItemsDao.selectAllPurchasingApplyItems();
        return rmtPurchasingApplyItemsList;
    }

}
